/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.govern;

import com.wtkj.vo.dzzf.base.kfwd.OBU;
import com.wtkj.vo.dzzf.base.kfzx.ObuGoods;
import com.wttech.dzzf.process.constant.UserConstants;
import com.wttech.dzzf.process.dao.DataGovernDao;
import com.wttech.dzzf.process.dao.TransferUserInfoDao;
import com.wttech.dzzf.process.service.base.BaseInfoService;
import com.wttech.dzzf.process.util.BusinessUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.wttech.dzzf.check.moduleSet.CheckOBUUpload_12.*;

/**
 * OBU信息治理服务
 *
 * @author MaShibo
 * @date 2017/12/7.
 */
@Service
public class ObuInfoGovernService {

	private static final Logger Obu = LoggerFactory.getLogger("Obu");

	@Resource
	private DataGovernDao dataGovernDao;

	@Resource
	private BaseInfoService baseInfoService;

	@Resource
	private TransferUserInfoDao transferUserInfoDao;

	void governObu(OBU obu) {

		String obuListId = obu.getObuListID();
		String id = obu.getObuId();
		String obuNo = obu.getObuNo();
		ObuGoods obuGoods = dataGovernDao.queryObuGoodsInfoByNo(obuNo);

		String result;
		result = checkId(id);
		if (baseInfoService.needOutput(result)) {
			Obu.info("OBU信息【{}】，合同号【{}】错误【{}】", new Object[]{obuListId, id, result});
		}

		if (obuGoods != null) {
			ObuGoods updateGoods = new ObuGoods();
			boolean isUpdated = false;
			updateGoods.setId(obuGoods.getId());

			Integer brand = obuGoods.getBrand();
			result = checkBrand(brand);
			if (baseInfoService.needOutput(result)) {
				updateGoods.setBrand(BusinessUtils.determineObuBrand(id, obuNo));
				isUpdated = true;
			}

			String model = obuGoods.getModel();
			result = checkModel(model);
			if (baseInfoService.needOutput(result)) {
				updateGoods.setModel(BusinessUtils.determineObuModel(brand, obuNo));
				isUpdated = true;
			}

			if (isUpdated) {
				transferUserInfoDao.updateDzzfObject(updateGoods);
			}
		}

	}
}
